package com.ruoyi.iot.dataprocessing.enums;
import java.util.Arrays;

/**
 * 健康数据MQTT主题枚举
 */
public enum HealthTopicEnum {

    HEART_RATE(1, "heartRate", "/health/customer/heartRate/"),
    OXYGEN(2, "oxygen", "/health/customer/oxygen/"),
    BREATH_RATE(3, "breathRate", "/health/customer/breathRate/"),
    GLUCOSE(4, "glucose", "/health/customer/glucose/"),
    BLOOD_PRESSURE(5, "bloodPressure", "/health/customer/bloodPressure/"),
    HEALTH_SCORE(6, "healthScore", "/health/customer/healthScore/"),
    ORGAN_FUNCTION(7, "organFunction", "/health/customer/organFunction/");

    private final Integer type;
    private final String code;
    private final String topic;

    HealthTopicEnum(Integer type, String code, String topic) {
        this.type = type;
        this.code = code;
        this.topic = topic;
    }

    public Integer getType() {
        return type;
    }

    public String getCode() {
        return code;
    }

    public String getTopic() {
        return topic;
    }

    /**
     * 根据code获取枚举
     * @param code 代码
     * @return 枚举对象
     */
    public static HealthTopicEnum getByCode(String code) {
        return Arrays.stream(values())
                .filter(item -> item.code.equals(code))
                .findFirst()
                .orElse(null);
    }

    /**
     * 根据type获取枚举
     * @param type 类型
     * @return 枚举对象
     */
    public static HealthTopicEnum getByType(Integer type) {
        return Arrays.stream(values())
                .filter(item -> item.type.equals(type))
                .findFirst()
                .orElse(null);
    }
}